package com.sourcetrip.binarytree;


import com.sourcetrip.raw.adt.MyBinarySearchTree;

/**
 * @author: ZhouBert
 * @date: 2020/11/24
 * @description:	测试 MyBinarySearchTree 的健壮性
 */
public class MyBinarySearchTreeTest01 {

	public static void main(String[] args) {
		MyBinarySearchTree<Integer> binarySearchTree = new MyBinarySearchTree<>();
		binarySearchTree.add(10);
		binarySearchTree.add(5);
		binarySearchTree.add(3);
		binarySearchTree.add(4);
		binarySearchTree.add(15);
		binarySearchTree.add(13);
		binarySearchTree.add(14);
		System.out.println(binarySearchTree.toString());

		testBigNSearch();
	}


	/**
	 * 严重的 bug !
	 * 由于 MyBinarySearchTree 使用了递归去查询，结果这个 test 导致 StackOverflow!!!
	 */
	static void testBigNSearch(){
		MyBinarySearchTree<Integer> tree = new MyBinarySearchTree<>();
		for (int i = 0; i < 100000; i++) {
			tree.add(i);
		}
		System.out.println("begin:" + System.currentTimeMillis());
		boolean contains = tree.contains(9999);
		System.out.println("contains = " + contains);
		System.out.println("end:" + System.currentTimeMillis());
	}
}
